define([], function() {
    return {
        appInit: function(_app) {
            appObj = {
                search: function(obj) {
                    var param = {};
                    $.each($("#fm-app").serializeArray(), function(k, v) {
                        var key = $.trim(v.name);
                        var value = $.trim(v.value);
                        param[key] = value;
                    });
                    $('#appTable').datagrid('load', param);
                },
                reset: function(obj) {
                    $('#fm-app').form('reset');
                },
                add: function(obj) {
                    $('#dlg-app-edit').dialog('close');
                    $('#dlg-app-add').dialog('open').dialog('center').dialog('setTitle', '新增应用');
                    $('#fm-app-add').form('clear');
                },
                edit: function(obj) {
                    var json = $(obj).attr('data');
                    var app = $.parseJSON(json);
                    var title = '编辑应用(' + app.name + ')';
                    $('#fm-app-edit').form('clear');
                    $('#dlg-app-add').dialog('close');
                    $('#dlg-app-edit').dialog({
                        onOpen: function() {
                            var body = $(this).panel('body');
                            $.each(app, function(k, v) {
                                body.find('#app-edit-' + k).textbox({
                                    value: v
                                }).attr("placeholder", $(this).attr("placeholder"));
                            });
                        }
                    });
                    $('#dlg-app-edit').dialog('open').dialog('center').dialog('setTitle', title);
                },
                save: function(obj) {
                    var url = _app.get_add_url;
                    $('#fm-app-add').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(data) {
                            var _data = $.parseJSON(data);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-add').dialog('close');
                            $("#appTable").datagrid('reload');
                        }
                    });
                },
                modify: function(obj) {
                    var url = _app.get_edit_url;
                    $('#fm-app-edit').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(data) {
                            var _data = $.parseJSON(data);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-edit').dialog('close');
                            $("#appTable").datagrid('reload');
                        }
                    });
                },
                disable: function(obj) {
                    var json = $(obj).attr('data');
                    var app = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要隐藏应用-<' + app['name'] + '>', function(r) {
                        if (r) {
                            var url = _app.get_edit_url;
                            var data = {
                                'id': app['id'],
                                'name': app['name'],
                                'host': app['host'],
                                'key': app['key'],
                                'desc': app['desc'],
                                'status': '0',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appTable").datagrid('reload');
                                }
                            });
                        }
                    });
                },
                enable: function(obj) {
                    var json = $(obj).attr('data');
                    var app = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要启用应用-<' + app['name'] + '>', function(r) {
                        if (r) {
                            var url = _app.get_edit_url;
                            var data = {
                                'id': app['id'],
                                'name': app['name'],
                                'host': app['host'],
                                'key': app['key'],
                                'desc': app['desc'],
                                'status': '1',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appTable").datagrid('reload');
                                }
                            });
                        }
                    });
                },
                cancel: function(obj) {
                    $('#dlg-app-add').dialog('close');
                    $('#dlg-app-edit').dialog('close');
                }
            };
            $("#appTable").datagrid({
                url: _app.get_list_url,
                method: 'GET',
                queryParams: {
                    type: 'ajax',
                    app_id: $("").val(),
                },
                striped: false,
                fit: true,
                border: false,
                fitColumns: true,
                singleSelect: true,
                stripedrd: true,
                rownumbers: true,
                pagination: true,
                idField: 'id',
                nowrap: false,
                pageSize: 35,
                pageList: [35, 40, 50, 100],
                showFooter: true,
                sortName: 'id',
                sortOrder: 'ASC',
                remoteSort: true,
                scrollbarSize: 0,
                columns: [
                    [{
                        field: 'id',
                        checkbox: true,
                    }, {
                        field: 'name',
                        title: '名称',
                        width: '8%',
                        align: 'left'
                    }, {
                        field: 'host',
                        title: '域名',
                        width: '12%',
                        align: 'left'
                    }, {
                        field: 'key',
                        title: '签名',
                        width: '8%',
                        align: 'left'
                    }, {
                        field: 'secret',
                        title: '秘钥',
                        width: '12%',
                        align: 'center'
                    }, {
                        field: 'desc',
                        title: '描述',
                        width: '10%',
                        align: 'left',
                        sortable: false
                    }, {
                        field: 'status',
                        title: '状态',
                        width: '5%',
                        align: 'center',
                        sortable: true,
                        formatter: function(value, data, index) {
                            var str = '';
                            if (value == 1) str = '<a style="background:#5cb85c;display:block;color:white;">正常</a>';
                            if (value == 0) str = '<a style="background:#f0ad4e;display:block;color:white;">隐藏</a>';
                            if (value == 3) str = '<a style="background:#d9534f;display:block;color:white;">软删</a>';
                            return str;
                        }
                    }, {
                        field: 'operator_name',
                        title: '添加人',
                        width: '5%',
                        align: 'center'
                    }, {
                        field: 'deleted_at',
                        title: '详情',
                        width: '15%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            var auth_url = _app.get_auth_url + '?app_id=' + data['id'];
                            var authObj = '{"iconCls": "icon-application_key","url":"' + auth_url + '","text": "权限列表","update":true}';
                            str += "<a onClick='commonObj.openTab(" + authObj + ");' class='loan_app_auth_button'></a>";
                            //
                            var group_url = _app.get_group_url + '?app_id=' + data['id'];
                            var groupObj = '{"iconCls": "icon-group","url":"' + group_url + '","text": "角色分组","update":true}';
                            str += "<a onClick='commonObj.openTab(" + groupObj + ");' class='loan_app_group_button'></a>";
                            //
                            // var staff_url = _app.get_staff_url + '?app_id=' + data['id'];
                            // var staffObj = '{"iconCls": "icon-report_user","url":"' + staff_url + '","text": "用户","update":true}';
                            // str += "<a onClick='commonObj.openTab(" + staffObj + ");' class='loan_app_user_button'></a>";
                            return str;
                        }
                    }, {
                        field: 'created_at',
                        title: '添加时间',
                        width: '10%',
                        align: 'center',
                        sortable: true
                    }, {
                        field: 'updated_at',
                        title: '操作',
                        width: '13%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            str += "<a class='loan_app_edit_button' data='" + JSON.stringify(data) + "' onclick='appObj.edit(this);'></a>";
                            if (data['status'] == 0) {
                                str += "<a data='" + JSON.stringify(data) + "' onClick='appObj.enable(this);' class='loan_app_enable_button'></a>";
                            } else {
                                str += "<a data='" + JSON.stringify(data) + "' onClick='appObj.disable(this);' class='loan_app_disable_button'></a>";
                            }
                            return str;
                        }
                    }]
                ],
                toolbar: '#appToolBar',
                onBeforeLoad: function(param) {},
                onLoadSuccess: function(data) {
                    $(".loan_app_edit_button").linkbutton({
                        text: '编辑',
                        plain: true,
                        iconCls: 'icon-application_edit'
                    });
                    $(".loan_app_disable_button").linkbutton({
                        text: '隐藏',
                        plain: true,
                        iconCls: 'icon-application_stop'
                    });
                    $(".loan_app_enable_button").linkbutton({
                        text: '启用',
                        plain: true,
                        iconCls: 'icon-application_start'
                    });
                    $(".loan_app_auth_button").linkbutton({
                        text: '权限列表',
                        plain: true,
                        iconCls: 'icon-application_key'
                    });
                    $(".loan_app_group_button").linkbutton({
                        text: '角色分组',
                        plain: true,
                        iconCls: 'icon-group'
                    });
                    // $(".loan_app_user_button").linkbutton({
                    //     text: '用户',
                    //     plain: true,
                    //     iconCls: 'icon-report_user'
                    // });
                    $('#appTable').datagrid('fixRowHeight');
                },
                onLoadError: function() {},
                onClickCell: function(rowIndex, field, value) {},
                onDblClickRow: function(rowIndex, rowData) {},
                onAfterEdit: function(rowIndex, rowData, changes) {}
            });
        },
        appAuthInit: function(_appAuth) {
            appAuthObj = {
                search: function(obj) {
                    var param = {};
                    $.each($("#fm-app-auth").serializeArray(), function(k, v) {
                        var key = $.trim(v.name);
                        var value = $.trim(v.value);
                        param[key] = value;
                    });
                    console.log(param);
                    $('#appAuthTable').treegrid('load', param);
                },
                reset: function(obj) {
                    $('#fm-app-auth').form('reset');
                },
                build: function(obj) {
                    alert('build');
                },
                add: function(obj) {
                    $('#dlg-app-auth-edit').dialog('close');
                    $('#fm-app-auth-add').form('clear');
                    //初始化数据
                    var appAuth = $.parseJSON($(obj).attr('data'));
                    $("#app-auth-add-app_id").combobox('select', appAuth['app_id']);
                    //初始化树形下拉框
                    if (appAuth['id'] != 0) {
                        var data = [];
                        data.push({
                            'id': appAuth['id'],
                            'name': appAuth['name']
                        });
                        $('#app-auth-add-parent_id').combotreegrid({
                            value: appAuth['id'],
                            width: '50%',
                            panelWidth: 360,
                            data: data,
                            idField: 'id',
                            textField: appAuth['name'],
                            treeField: 'name',
                            scrollbarSize: 0,
                            columns: [
                                [{
                                    field: 'name',
                                    title: '权限名称',
                                    width: '98%',
                                    align: 'left'
                                }]
                            ]
                        });
                    } else {
                        $('#app-auth-add-parent_id').combotreegrid({
                            value: appAuth['id'],
                            width: '50%',
                            panelWidth: 360,
                            method: 'GET',
                            labelPosition: 'top',
                            idField: 'id',
                            url: _appAuth.get_list_url + '?type=ajax',
                            idField: 'id',
                            textField: appAuth['name'],
                            treeField: 'name',
                            scrollbarSize: 0,
                            columns: [
                                [{
                                    field: 'name',
                                    title: '权限名称',
                                    width: '98%',
                                    align: 'left'
                                }]
                            ]
                        });
                        $("#app-auth-add-app_id").combobox("enable");
                        $("#app-auth-add-parent_id").combobox("enable");
                    }
                    $('#dlg-app-auth-add').dialog('open').dialog('center').dialog('setTitle', '新增应用');
                },
                edit: function(obj) {
                    //初始化数据
                    var json = $(obj).attr('data');
                    var appAuth = $.parseJSON(json);
                    var title = '编辑应用(' + appAuth.name + ')';
                    $('#fm-app-auth-edit').form('clear');
                    $('#dlg-app-auth-add').dialog('close');
                    $("#app-auth-edit-app_id").combobox('select', appAuth['app_id']);
                    $('#dlg-app-auth-edit').dialog({
                        onOpen: function() {
                            var body = $(this).panel('body');
                            $.each(appAuth, function(k, v) {
                                if (k != 'app_id') {
                                    body.find('#app-auth-edit-' + k).textbox({
                                        value: v
                                    }).attr("placeholder", $(this).attr("placeholder"));
                                }
                            });
                        }
                    });
                    //初始化树形下拉框
                    $('#app-auth-edit-parent_id').combotreegrid({
                        value: appAuth['id'],
                        width: '50%',
                        panelWidth: 360,
                        method: 'GET',
                        labelPosition: 'top',
                        url: _appAuth.get_list_url + '?type=ajax&app_id=' + appAuth['app_id'] + '&parent_id=' + appAuth['parent_id'],
                        idField: 'id',
                        textField: appAuth['name'],
                        treeField: 'name',
                        scrollbarSize: 0,
                        columns: [
                            [{
                                field: 'name',
                                title: '权限名称',
                                width: '98%',
                                align: 'left'
                            }]
                        ]
                    });
                    $('#dlg-app-auth-edit').dialog('open').dialog('center').dialog('setTitle', title);
                },
                save: function(obj) {
                    var url = _appAuth.get_add_url;
                    $('#fm-app-auth-add').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(data) {
                            var _data = $.parseJSON(data);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-auth-add').dialog('close');
                            $("#appAuthTable").treegrid('reload');
                        }
                    });
                },
                modify: function(obj) {
                    var url = _appAuth.get_edit_url;
                    $('#fm-app-auth-edit').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(data) {
                            var _data = $.parseJSON(data);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-auth-edit').dialog('close');
                            $("#appAuthTable").treegrid('reload');
                        }
                    });
                },
                disable: function(obj) {
                    var json = $(obj).attr('data');
                    var appAuth = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要隐藏权限-<' + appAuth['name'] + '>', function(r) {
                        if (r) {
                            var url = _appAuth.get_edit_url;
                            var data = {
                                'id': appAuth['id'],
                                'name': appAuth['name'],
                                'parent_id': appAuth['parent_id'],
                                'app_id': appAuth['app_id'],
                                'uri': appAuth['uri'],
                                'css': appAuth['css'],
                                'is_show': appAuth['is_show'],
                                'desc': appAuth['desc'],
                                'status': '0',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appAuthTable").treegrid('reload');
                                }
                            });
                        }
                    });
                },
                enable: function(obj) {
                    var json = $(obj).attr('data');
                    var appAuth = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要启用权限-<' + appAuth['name'] + '>', function(r) {
                        if (r) {
                            var url = _appAuth.get_edit_url;
                            var data = {
                               'id': appAuth['id'],
                                'name': appAuth['name'],
                                'parent_id': appAuth['parent_id'],
                                'app_id': appAuth['app_id'],
                                'uri': appAuth['uri'],
                                'css': appAuth['css'],
                                'is_show': appAuth['is_show'],
                                'desc': appAuth['desc'],
                                'status': '1',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appAuthTable").treegrid('reload');
                                }
                            });
                        }
                    });
                },
                cancel: function(obj) {
                    $('#dlg-app-auth-add').dialog('close');
                    $('#dlg-app-auth-edit').dialog('close');
                }
            };
            var queryParams = {};
            $.each($("#fm-app-auth").serializeArray(), function(k, v) {
                var key = $.trim(v.name);
                var value = $.trim(v.value);
                queryParams[key] = value;
            });
            $("#appAuthTable").treegrid({
                url: _appAuth.get_list_url,
                method: 'GET',
                queryParams: queryParams,
                striped: false,
                fit: true,
                border: false,
                fitColumns: true,
                singleSelect: true,
                stripedrd: true,
                rownumbers: true,
                pagination: false,
                idField: 'id',
                treeField: 'name',
                autoRowHeight: false,
                nowrap: false,
                pageSize: 10,
                pageList: [10, 20, 30, 100],
                showFooter: true,
                sortName: 'id',
                sortOrder: 'ASC',
                remoteSort: true,
                scrollbarSize: 0,
                columns: [
                    [{
                        field: 'name',
                        title: '名称',
                        width: '15%',
                        align: 'left'
                    }, {
                        field: 'uri',
                        title: '权限',
                        width: '15%',
                        align: 'left'
                    }, {
                        field: 'css',
                        title: '样式[图标]',
                        width: '14%',
                        align: 'left'
                    }, {
                        field: 'desc',
                        title: '描述',
                        width: '10%',
                        align: 'left',
                        sortable: false
                    }, {
                        field: 'is_show',
                        title: '显隐',
                        width: '5%',
                        align: 'center',
                        formatter: function(value, data, index) {
                            var str = '';
                            if (value == 1) str = '<a style="background:#5cb85c;display:block;color:white;">显</a>';
                            if (value == 0) str = '<a style="background:#f0ad4e;display:block;color:white;">隐</a>';
                            return str;
                        }
                    }, {
                        field: 'status',
                        title: '状态',
                        width: '5%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            if (value == 1) str = '<a style="background:#5cb85c;display:block;color:white;">正常</a>';
                            if (value == 0) str = '<a style="background:#f0ad4e;display:block;color:white;">隐藏</a>';
                            if (value == 3) str = '<a style="background:#d9534f;display:block;color:white;">软删</a>';
                            return str;
                        }
                    }, {
                        field: 'operator_name',
                        title: '添加人',
                        width: '5%',
                        align: 'center'
                    }, {
                        field: 'created_at',
                        title: '添加时间',
                        width: '10%',
                        align: 'center',
                        sortable: true
                    }, {
                        field: 'updated_at',
                        title: '操作',
                        width: '20%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            str += "<a class='loan_app_auth_edit_button' data='" + JSON.stringify(data) + "' onclick='appAuthObj.edit(this);'></a>";
                            str += "<a class='loan_app_auth_add_button' data='" + JSON.stringify(data) + "' onclick='appAuthObj.add(this);'></a>";
                            if (data['status'] == 0) {
                                str += "<a data='" + JSON.stringify(data) + "' onClick='appAuthObj.enable(this);' class='loan_app_auth_enable_button'></a>";
                            } else {
                                str += "<a data='" + JSON.stringify(data) + "' onClick='appAuthObj.disable(this);' class='loan_app_auth_disable_button'></a>";
                            }
                            return str;
                        }
                    }]
                ],
                toolbar: '#appAuthToolBar',
                onBeforeLoad: function(param) {},
                onLoadSuccess: function(data) {
                    $(".loan_app_auth_edit_button").linkbutton({
                        text: '编辑',
                        plain: true,
                        iconCls: 'icon-application_edit'
                    });
                    $(".loan_app_auth_add_button").linkbutton({
                        text: '新增子权限',
                        plain: true,
                        iconCls: 'icon-application_add'
                    });
                    $(".loan_app_auth_disable_button").linkbutton({
                        text: '隐藏',
                        plain: true,
                        iconCls: 'icon-application_stop'
                    });
                    $(".loan_app_auth_enable_button").linkbutton({
                        text: '启用',
                        plain: true,
                        iconCls: 'icon-application_start'
                    });
                    $(".loan_app_auth_auth_button").linkbutton({
                        text: '权限',
                        plain: true,
                        iconCls: 'icon-application_key'
                    });
                    $(".loan_app_auth_group_button").linkbutton({
                        text: '角色分组',
                        plain: true,
                        iconCls: 'icon-group'
                    });
                    $(".loan_app_auth_user_button").linkbutton({
                        text: '用户',
                        plain: true,
                        iconCls: 'icon-report_user'
                    });
                    $('#appAuthTable').treegrid('fixRowHeight');
                },
                onLoadError: function() {},
                onClickCell: function(rowIndex, field, value) {},
                onDblClickRow: function(rowIndex, rowData) {},
                onAfterEdit: function(rowIndex, rowData, changes) {}
            });
        },
        appGroupInit: function(_appGroup) {
            appGroupObj = {
                search: function(obj) {
                    var param = {};
                    $.each($("#fm-app-group").serializeArray(), function(k, v) {
                        var key = $.trim(v.name);
                        var value = $.trim(v.value);
                        param[key] = value;
                    });
                    $('#appGroupTable').datagrid('load', param);
                },
                reset: function(obj) {
                    $('#fm-app-group').form('reset');
                },
                build: function(obj) {
                    alert('build');
                },
                add: function(obj) {
                    $('#dlg-app-group-edit').dialog('close');
                    $('#fm-app-group-add').form('clear');
                    //初始化数据
                    var appGroup = $.parseJSON($(obj).attr('data'));
                    $("#app-group-add-app_id").combobox('select', appGroup['app_id']);
                    //获取当前分组已经关联的权限
                    var url = _appGroup.get_group_auth_url;
                    var data = {
                        'group_id': appGroup['id']
                    };
                    //通过ajax方法获取数据方法
                    var selected_auths = commonObj.toGetData(url, data);
                    //初始化树形下拉框
                    $('#app-group-add-auth_id').combotree({
                        width: '60%',
                        method: 'GET',
                        url: _appGroup.get_auth_url + '?type=ajax&style=tree&app_id=' + appGroup['app_id'],
                        textField: 'name',
                        cascadeCheck: false,
                        multiple: true,
                        value: selected_auths,
                    });
                    //
                    $('#dlg-app-group-add').dialog('open').dialog('center').dialog('setTitle', '新增分组');
                },
                edit: function(obj) {
                    //初始化数据
                    var json = $(obj).attr('data');
                    var appGroup = $.parseJSON(json);
                    var title = '编辑分组(' + appGroup.name + ')';
                    $('#fm-app-group-edit').form('clear');
                    $('#dlg-app-group-add').dialog('close');
                    $("#app-group-edit-app_id").combobox('select', appGroup['app_id']);
                    //获取当前分组已经关联的权限
                    var url = _appGroup.get_group_auth_url;
                    var data = {
                        'group_id': appGroup['id']
                    };
                    //通过ajax方法获取数据方法
                    var selected_auths = commonObj.toGetData(url, data);
                    //初始化树形下拉框
                    $('#app-group-edit-auth_id').combotree({
                        width: '60%',
                        method: 'GET',
                        url: _appGroup.get_auth_url + '?type=ajax&style=tree&app_id=' + appGroup['app_id'],
                        textField: 'name',
                        cascadeCheck: false,
                        multiple: true,
                        value: selected_auths,
                    });
                    //
                    $('#dlg-app-group-edit').dialog({
                        onOpen: function() {
                            var body = $(this).panel('body');
                            $.each(appGroup, function(k, v) {
                                if (k != 'app_id') {
                                    body.find('#app-group-edit-' + k).textbox({
                                        value: v
                                    }).attr("placeholder", $(this).attr("placeholder"));
                                }
                            });
                        }
                    });
                    //
                    $('#dlg-app-group-edit').dialog('open').dialog('center').dialog('setTitle', title);
                },
                save: function(obj) {
                    var url = _appGroup.get_add_url;
                    $('#fm-app-group-add').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(data) {
                            var _data = $.parseJSON(data);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-group-add').dialog('close');
                            $("#appGroupTable").datagrid('reload');
                        }
                    });
                },
                modify: function(obj) {
                    var url = _appGroup.get_edit_url;
                    $('#fm-app-group-edit').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(json) {
                            if (json['status']) {
                                $.messager.alert('error', json['msg'], 'error');
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-group-edit').dialog('close');
                            $("#appGroupTable").datagrid('reload');
                        }
                    });
                },
                disable: function(obj) {
                    var json = $(obj).attr('data');
                    var appGroup = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要隐藏分组-<' + appGroup['name'] + '>', function(r) {
                        if (r) {
                            var url = _appGroup.get_edit_url;
                            var data = {
                                'type': 'modify',
                                'id': appGroup['id'],
                                'name': appGroup['name'],
                                'app_id': appGroup['app_id'],
                                'desc': appGroup['desc'],
                                'status': '0',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appGroupTable").datagrid('reload');
                                }
                            });
                        }
                    });
                },
                enable: function(obj) {
                    var json = $(obj).attr('data');
                    var appGroup = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要启用分组-<' + appGroup['name'] + '>', function(r) {
                        if (r) {
                            var url = _appGroup.get_edit_url;
                            var data = {
                                'type': 'modify',
                                'id': appGroup['id'],
                                'name': appGroup['name'],
                                'app_id': appGroup['app_id'],
                                'desc': appGroup['desc'],
                                'status': '1',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appGroupTable").datagrid('reload');
                                }
                            });
                        }
                    });
                },
                cancel: function(obj) {
                    $('#dlg-app-group-add').dialog('close');
                    $('#dlg-app-group-edit').dialog('close');
                }
            };
            var queryParams = {};
            $.each($("#fm-app-group").serializeArray(), function(k, v) {
                var key = $.trim(v.name);
                var value = $.trim(v.value);
                queryParams[key] = value;
            });
            //
            var appJson = _appGroup.get_app_json;
            var appArr = $.parseJSON(appJson);
            $("#appGroupTable").datagrid({
                url: _appGroup.get_list_url,
                method: 'GET',
                queryParams: queryParams,
                striped: false,
                fit: true,
                border: false,
                fitColumns: true,
                singleSelect: true,
                stripedrd: true,
                rownumbers: true,
                pagination: true,
                idField: 'id',
                nowrap: false,
                pageSize: 35,
                pageList: [35, 40, 50, 100],
                showFooter: true,
                sortName: 'app_id',
                sortOrder: 'ASC',
                remoteSort: true,
                scrollbarSize: 0,
                columns: [
                    [{
                        field: 'id',
                        checkbox: true,
                    }, {
                        field: 'name',
                        title: '名称',
                        width: '8%',
                        align: 'left'
                    }, {
                        field: 'app_id',
                        title: '应用名称',
                        width: '12%',
                        align: 'left',
                        sortable: false,
                        formatter: function(value, data, index) {
                            return appArr[value];
                        }
                    }, {
                        field: 'desc',
                        title: '描述',
                        width: '20%',
                        align: 'left',
                        sortable: false
                    }, {
                        field: 'operator_name',
                        title: '添加人',
                        width: '5%',
                        align: 'center'
                    }, {
                        field: 'created_at',
                        title: '添加时间',
                        width: '10%',
                        align: 'center',
                        sortable: true
                    }, {
                        field: 'updated_at',
                        title: '更新时间',
                        width: '13%',
                        align: 'center',
                        sortable: false,
                    }, {
                        field: 'status',
                        title: '状态',
                        width: '5%',
                        align: 'center',
                        sortable: true,
                        formatter: function(value, data, index) {
                            var str = '';
                            if (value == 1) str = '<a style="background:#5cb85c;display:block;color:white;">正常</a>';
                            if (value == 0) str = '<a style="background:#f0ad4e;display:block;color:white;">隐藏</a>';
                            if (value == 3) str = '<a style="background:#d9534f;display:block;color:white;">软删</a>';
                            return str;
                        }
                    }, {
                        field: 'deleted_at',
                        title: '操作',
                        width: '25%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            var json = JSON.stringify(data);
                            str += "<a class='loan_app_auth_edit_button' data='" + json + "' onclick='appGroupObj.edit(this);'></a>";
                            if (data['status'] == 0) {
                                str += "<a data='" + json + "' onClick='appGroupObj.enable(this);' class='loan_app_auth_enable_button'></a>";
                            } else {
                                str += "<a data='" + json + "' onClick='appGroupObj.disable(this);' class='loan_app_auth_disable_button'></a>";
                            }
                            return str;
                        }
                    }]
                ],
                toolbar: '#appGroupToolBar',
                onBeforeLoad: function(param) {},
                onLoadSuccess: function(data) {
                    $(".loan_app_auth_edit_button").linkbutton({
                        text: '编辑',
                        plain: true,
                        iconCls: 'icon-application_edit'
                    });
                    $(".loan_app_auth_disable_button").linkbutton({
                        text: '禁用',
                        plain: true,
                        iconCls: 'icon-application_stop'
                    });
                    $(".loan_app_auth_enable_button").linkbutton({
                        text: '启用',
                        plain: true,
                        iconCls: 'icon-application_start'
                    });
                    $('#appGroupTable').datagrid('fixRowHeight');
                },
                onLoadError: function() {},
                onClickCell: function(rowIndex, field, value) {},
                onDblClickRow: function(rowIndex, rowData) {},
                onAfterEdit: function(rowIndex, rowData, changes) {}
            });
        }
    }
});